import java.util.ArrayList;
import java.util.List;

public class Hand
{
    private List<Card> hand = new ArrayList<>();
    private static final int ACE_MAX_VALUE = 11;
    private static final int ACE_MIN_VALUE = 1;
    

    void addCard(Card card)
    {
        hand.add(card);
    }
    
    public int getScore()
    {
        int total = 0;
        int aceCounter = 0;
        for(Card c : hand)
        {
            if(c.isAce())
            {
                aceCounter++;
                total+= ACE_MAX_VALUE;
            }
            else
            {
                total += c.getNumericValue();
            }
            while(total > GameManager.BLACKJACK && aceCounter > 0)
            {
                total -= ACE_MAX_VALUE;
                total += ACE_MIN_VALUE;
            }
        }
        return total;
    }

    @Override
    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        for(Card c : hand)
            sb.append(c).append("\n");
        sb.append("Score: ").append(getScore());
        return sb.toString();
    }

    void clear()
    {
        hand.clear();
    }
}
